package parser

import (
	"gitee.com/volvoxc60/go-crawler/engine"
	"regexp"
)

//todo 要先写针对city的test，然后把返回的parsefunc拼装
const CityRe = `<a href="(http://album.zhenai.com/u/[0-9]+)"[^>]*>([^<]+)</a>`

func ParseCity(contents []byte) (result engine.ParseResult) {
	res := regexp.MustCompile(CityRe)
	matches := res.FindAllSubmatch(contents, -1)
	limit := 4
	for _, m := range matches {
		name := string(m[2])
		result.Items = append(result.Items, "User is "+name)
		//time.Sleep(500*time.Microsecond)

		limit--
		if limit == 0 {
			break
		}

		result.Requests = append(result.Requests, engine.Request{
			Url: string(m[1]),
			//ParseFunc: ParseProfile,
			ParseFunc: func(contents []byte) engine.ParseResult {
				return ParseProfile(contents, name)
			},
		})
	}
	return result
}
